package com.hinnotek.warehouse.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.google.gson.GsonBuilder
import com.hinnotek.warehouse.api.WarehouseApi
import com.hinnotek.warehouse.bean.WarehourseApplyFormDevicesProjects
import com.hinnotek.warehouse.utils.StringUtils
import com.lee.common.network.getRequestBody
import com.lee.common.utils.SharedPreUtils
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor() :
    BaseViewModel() {

    var userName = ObservableField<String>()
    var userPass = ObservableField<String>()

    var pass1 = ObservableField<String>()
    var pass2 = ObservableField<String>()
    var pass3 = ObservableField<String>()

    private val login = Transformations.switchMap(refreshTrigger) {
        val name = userName.get().toString()
        val pass = userPass.get().toString()
        api.appLogin(name, pass)
    }

    private val modifyPass = Transformations.switchMap(refreshTrigger) {
        val pass1 = pass1.get().toString()
        val pass2 = pass2.get().toString()
        val userId = SharedPreUtils.getInteger("userId", 0)
        api.changePass(userId, pass1, pass2)
    }

    val loginPage = mapData(login)

    val modifyPassPage = mapData(modifyPass)


}